<template>
  <el-row :gutter="24" class="pl80">
    <el-col>
      <h2>考评记录</h2>
    </el-col>
    <el-col>
      <e-table
        style="width: 98%"
        @getList="handleGetList"
        :tableData="tableData"
        :columns="columns"
        :loading="loading"
        :total="total"
      >
        <el-table-column label="结果" slot="result" align="center">
          <template slot-scope="scope">{{ handleData(scope.row.eval_result) }}</template>
        </el-table-column>
      </e-table>
    </el-col>
  </el-row>
</template>

<script>
import { getSession } from '@/utils/util'
import { getUserAppraisalRecord } from '@/api/archives'

export default {
  data() {
    return {
      tableData: [],
      loading: false,
      columns: [
        {
          label: '考评类型',
          prop: 'eval_type'
        },
        {
          label: '方案任务',
          prop: 'task_name'
        },
        {
          label: '考评等级',
          prop: 'eval_level'
        },
        {
          label: '时间',
          prop: 'eval_cycle'
        },
        { slot: 'result' }
        // {
        //   label: '结果',
        //   prop: 'eval_result'
        // }
      ],
      total: 1,
      queryParam: {
        pageSize: 10,
        pageNo: 1
      },
      userRow: {}
    }
  },
  created() {
    if (this.$route.query.userRow) {
      this.userRow = JSON.parse(this.$route.query.userRow)
    } else {
      this.userRow = getSession('userRow')
    }
    this.handleGetList({ userId: this.userRow.userId })
  },
  methods: {
    handleData(str) {
      let arr = str.split(',')
      if (arr.length > 1) {
        if (arr[1] !== '0.00') {
          return arr[0] + '；总金额：' + arr[1]
        } else {
          return arr[0]
        }
      } else {
        return arr[0]
      }
    },
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)
      const res = await getUserAppraisalRecord(this.queryParam)
      console.log('reward res', res)

      if (res.data && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
